<!--
描述：试题检测信息组件
开发人：hqj
开发日期：2018年11月09日
修改人：
修改日期：
-->
<template lang="pug">
    div.kalix-article(v-if="pageShow")
        keep-alive
            div(style="height:100%;")
                div(style="height:100%;display: flex;flex-direction: column;")
                    div.frame-item(style="flex:1;")
                        keep-alive
                            kalix-table(bizKey="questionsTesting" title='试题检测信息列表' v-bind:targetURL="questionTestingURL"
                            v-bind:bizSearch="'QuestionsTestingSearch'" v-bind:toolbarBtnList="toolbarBtnList"
                            v-bind:btnList="btnList1" v-bind:customTableTool="customTableTool"
                            v-bind:isFixedColumn="isFixedColumn" ref="kalixTable1")
                                template(slot="tableColumnSlot")
                                    el-table-column(prop="subTypeName" label="题型子类" align="center" width="180px")
                                    el-table-column(prop="typeName" label="试题类别" align="center" width="150px")
                                    el-table-column(prop="questionId" label="ID" align="center" width="80px")
                                    el-table-column(prop="stem" label="题干" align="center" width="350px")
                                        template(slot-scope="scope")
                                            el-popover(trigger="hover" placement="top" width="350")
                                                | {{scope.row.stem}}
                                                div(slot="reference")
                                                    template(v-if="scope.row.stem && scope.row.stem.length > 20")
                                                        | {{scope.row.stem.substr(0, 20)}}...
                                                    template(v-else)
                                                        | {{scope.row.stem}}
                                    el-table-column(prop="createBy" label="创建者" align="center" width="120px")
                                    el-table-column(prop="creationDate" label="创建时间" align="center" width="180px")
                                        template(slot-scope="scope")
                                            i(class="el-icon-time")
                                            span {{scope.row.creationDate}}
                                    el-table-column(prop="delFlag" label="删除状态" align="center" width="120px")
                                        template(slot-scope="scope")
                                            template(v-if="scope.row.delFlag === '0'")
                                                el-tag(type="success") 有效
                                            template(v-else)
                                                el-popover(trigger="hover" placement="top" width="120")
                                                    | 试题删除原因
                                                    br
                                                    | {{scope.row.reason}}
                                                    div(slot="reference")
                                                        el-tag(type="danger") 已删除
                                    el-table-column(prop="compareFlag" label="排重比对状态" align="center" width="120px")
                                        template(slot-scope="scope")
                                            template(v-if="scope.row.compareFlag === '1'")
                                                el-tag(type="success") 已比对
                                            template(v-else)
                                                el-tag(type="danger") 未比对
                                    el-table-column(prop="repeatedFlag" label="排重处理状态" align="center" width="120px")
                                        template(slot-scope="scope")
                                            template(v-if="scope.row.repeatedFlag === '1'")
                                                el-tag(type="success") 已处理
                                            template(v-else)
                                                el-tag(type="danger") 未处理
                                    el-table-column(prop="checkFlag" label="审核状态" align="center" width="120px")
                                        template(slot-scope="scope")
                                            template(v-if="scope.row.checkFlag === '1'")
                                                el-tag(type="success") 已通过
                                            template(v-else-if="scope.row.checkFlag === '2'")
                                                el-popover(trigger="hover" placement="top" width="120")
                                                    | 审核未通过原因
                                                    br
                                                    | {{scope.row.checkReason}}
                                                    div(slot="reference")
                                                        el-tag(type="danger") 未通过
                                            template(v-else)
                                                el-tag 未审核
                                    el-table-column(prop="checker" label="审核员" align="center" width="120px")
                                    el-table-column(prop="checkDate" label="审核时间" align="center" width="180px")
                                        template(slot-scope="scope")
                                            i(class="el-icon-time")
                                            span {{scope.row.checkDate}}
                    div.frame-item(style="height:35%;")
                        keep-alive
                            kalix-table(bizKey="questionsRepeated" title='试题排重信息列表' v-bind:targetURL="questionRepeatedURL"
                            v-bind:toolbarBtnList="toolbarBtnList" v-bind:btnList="btnList2" v-bind:customTableTool="customTableTool"
                            v-bind:isFixedColumn="isFixedColumn" ref="kalixTable2")
                                template(slot="tableColumnSlot")
                                    el-table-column(prop="questionTypeName" label="题型" align="center" width="180px")
                                    el-table-column(prop="subTypeName" label="题型子类" align="center" width="180px")
                                    el-table-column(prop="questionId" label="ID" align="center" width="120px")
                                    el-table-column(prop="stem" label="题干" align="center" width="350px")
                                        template(slot-scope="scope")
                                            el-popover(trigger="hover" placement="top" width="350")
                                                | {{scope.row.stem}}
                                                div(slot="reference")
                                                    template(v-if="scope.row.stem && scope.row.stem.length > 20")
                                                        | {{scope.row.stem.substr(0, 20)}}...
                                                    template(v-else)
                                                        | {{scope.row.stem}}
                                    el-table-column(prop="createBy" label="创建者" align="center" width="120px")
                                    el-table-column(prop="creationDate" label="创建时间" align="center" width="180px")
                                        template(slot-scope="scope")
                                            i(class="el-icon-time")
                                            span {{scope.row.creationDate}}
                                    el-table-column(prop="checkFlag" label="审核状态" align="center" width="120px")
                                        template(slot-scope="scope")
                                            template(v-if="scope.row.checkFlag === '1'")
                                                el-tag(type="success") 已通过
                                            template(v-else-if="scope.row.checkFlag === '2'")
                                                el-popover(trigger="hover" placement="top" width="120")
                                                    | 审核未通过原因
                                                    br
                                                    | {{scope.row.checkReason}}
                                                    div(slot="reference")
                                                        el-tag(type="danger") 未通过
                                            template(v-else)
                                                el-tag 未审核
                                    el-table-column(prop="checker" label="审核员" align="center" width="120px")
                                    el-table-column(prop="checkDate" label="审核时间" align="center" width="180px")
                                        template(slot-scope="scope")
                                            i(class="el-icon-time")
                                            span {{scope.row.checkDate}}
                                    el-table-column(prop="similarity" label="相似度" align="center" width="200px")
    div(v-else) 题库功能已关闭，如需使用请联系管理员！
</template>

<script type="text/ecmascript-6">
    import FormModel from './model'
    import {QuestionTestingURL, RepeateURL} from '../../config.toml'
    import {questionTestingBtnList, questionTestingBtnList2} from '../config.js'
    /*import {availableQuestion} from '../../common.js'*/

    export default {
        name: 'kalix-enrolment-questionstesting',
        data() {
            return {
                pageShow: false,
                formModel: Object.assign({}, FormModel),
                toolbarBtnList: [
                    {id: 'add', isShow: false}
                ],
                btnList1: questionTestingBtnList,
                questionTestingURL: QuestionTestingURL,
                btnList2: questionTestingBtnList2,
                questionRepeatedURL: RepeateURL.replace('[beans]', 'completions') + '/-1',
                isFixedColumn: true
            }
        },
        components: {},
        created() {
            /*availableQuestion(this.axios, this.$KalixMessage, flag => {
             this.pageShow = flag
             })*/
            this.pageShow = true
        },
        activated() {
            // this.$KalixEventBus.$on(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK, this.onSearchClick)
        },
        deactivated() {
            // this.$KalixEventBus.$off(this.$KalixEventConfig.ON_SEARCH_BUTTON_CLICK)
        },
        watch: {},
        methods: {
            customTableTool(row, btnId, that) {
                switch (btnId) {
                    case 'repeat': {
                        this.onRepeat(row, that)
                        break
                    }
                    case 'saveRepeat': {
                        this.onSaveRepeat(row, that)
                        break
                    }
                    case 'deleteRepeat': {
                        this.onDeleteRepeat(row, that)
                        break
                    }
                }
            },
            onRepeat(row, table) {
                if (this.testingRow) {
                    if (this.testingRow.questionId !== row.questionId) {
                        // 执行查询试题排重数据
                        this.clearTableData(2)
                        this.testingRow = row
                        this.getRepeatedTableData(row)
                    }
                } else {
                    // 执行查询试题排重数据
                    this.clearTableData(2)
                    this.testingRow = row
                    this.getRepeatedTableData(row)
                }
            },
            onSaveRepeat(row, table) {
                let url = RepeateURL.replace('[beans]', row.questionBeans) + '/' + row.questionId
                this.axios.request({
                    method: 'PUT',
                    url: url,
                    params: {
                        questionId: row.questionId
                    }
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                    }
                    table.refresh()
                }).catch(() => {
                })
            },
            onDeleteRepeat(row, table) {
                let url = RepeateURL.replace('[beans]', row.questionBeans) + '/' + row.questionId
                this.axios.request({
                    method: 'DELETE',
                    url: url,
                    params: {
                        questionId: row.questionId
                    }
                }).then(response => {
                    if (response.data.success) {
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error(response.data.msg)
                    }
                    table.refresh()
                }).catch(() => {
                })
            },
            // 查询重复试题列表数据
            getRepeatedTableData(testingRow) {
                if (testingRow) {
                    this.questionRepeatedURL = RepeateURL.replace('[beans]', testingRow.questionBeans) + '/' + testingRow.questionId
                } else {
                    this.questionRepeatedURL = RepeateURL.replace('[beans]', 'completions') + '/-1'
                }
            },
            // 清除列表数据0全部，1检测试题，2排重试题
            clearTableData(num) {
                switch (num) {
                    case 0 :
                        this.$refs.kalixTable1.clearData()
                        this.$refs.kalixTable2.clearData()
                        break
                    case 1 :
                        this.$refs.kalixTable1.clearData()
                        break
                    case 2 :
                        this.$refs.kalixTable2.clearData()
                        break
                    default :
                        this.$refs.kalixTable1.clearData()
                        this.$refs.kalixTable2.clearData()
                        break
                }
            }
        }
    }
</script>

<style scoped lang="stylus">
</style>
